import React, { PureComponent } from "react";

import { EventEmitter } from "events";

const eventBus = new EventEmitter();

export default class App extends PureComponent {
  render() {
    return (
      <div>
        <span>app</span>
        <One></One>
        <button onClick={(e) => this.emitClick()}>add</button>
      </div>
    );
  }
  emitClick = () => {
    eventBus.emit("sayHello", 123, "hello One");
  };
}

class One extends PureComponent {
  componentDidMount() {
    eventBus.addListener("sayHello", (...args) => {
      console.log(args);
    });
  }

  componentWillMount() {
    eventBus.removeAllListeners("sayHello");
  }
  render() {
    return <div>One</div>;
  }
}
